package com.expre.user.controller;


import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.expre.user.pojo.UserInfo;
import com.expre.user.service.UserService;

@Controller
public class UserController {
	@Resource
	private UserService userService;
	@RequestMapping("/showUser")  
	public String toIndex(Map map){   
	   List ulist= (List) this.userService.getList();  
	   map.put("user", ulist);  
	   return "index";  
	}
	@RequestMapping("/toAdd")
	public String toAdd(Map map) {
		List clist=(List) this.userService.getCitys();
		map.put("city", clist);
		return "add";
	}
	@RequestMapping("/addUser")
	public String addUser(UserInfo user,Map map){   
		String str=userService.addUser(user);
		map.put("str", str);
		return "successful";
	}
	@RequestMapping("/delUser")
	public String delUser(int uid) {
		int i=userService.delete(uid);
		if(i>0) {
			return "successful";
		}else {			
			return "error";		
		}
	}
	@RequestMapping("/toUpdate")
	public String toUpdate(int uid,Map map) {
		UserInfo user=userService.update(uid);
		List clist=(List) this.userService.getCitys();
		map.put("city", clist);
		map.put("user", user);
		return "update";
	}
	@RequestMapping("/update")
	public String doUpdate() {
		int i=userService.updateUser();
		if(i>0) {
			return "successful";
		}else{
			return "error";
		}
	}
}
